import dayjs from 'dayjs';

/**
 * 将对象的时间中的范围属性转换为 RangePicker 可用的 value
 */
export function valueOfRangePickerProps<T extends Record<PropertyKey, any>>(
  obj: T,
  rangeDateKeys = ['start_time', 'end_time'] as [keyof T, keyof T],
) {
  const [startKey, endKey] = rangeDateKeys;
  return {
    'value': [dayjs(obj[startKey]), dayjs(obj[endKey])] as [dayjs.Dayjs, dayjs.Dayjs],
    'onUpdate:value': (newRangeDate: [any, any]) => {
      obj[startKey] = dayjs(newRangeDate[0]).valueOf() as any;
      obj[endKey] = dayjs(newRangeDate[1]).valueOf() as any;
    },
  };
}
